package com.itany.controller;


import com.alibaba.fastjson.annotation.JSONField;
import org.springframework.web.bind.annotation.*;

import java.util.*;


@RestController
@RequestMapping("/test")
public class TestController {


    @RequestMapping("/getSelectData")
    public List<Map<String,Object>> getSelectData(){
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        for(int i=0;i<10;i++){
             Map<String,Object> map = new HashMap<String,Object>();
             map.put("id",i+1);
             map.put("name","用户"+i);
             list.add(map);
        }
        return list;
    }

    @RequestMapping("/getData")
    public  Map<String,Object> getData(
            @RequestParam(name = "page",defaultValue = "1") Integer page,
            @RequestParam(name = "rows",defaultValue = "10") Integer rows,
            String name){
        Map<String,Object> map = new HashMap<String,Object>();
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        for(int i=0;i<10;i++){
            Map<String,Object> user = new HashMap<String,Object>();
            user.put("id",i+1);
            user.put("name","我的名称"+i);
            user.put("flag",i%2==0?1:2);
            if(i%2==0){
                Map<String,Object> vo = new HashMap<String,Object>();
                vo.put("vid",i+10);
                vo.put("vname","vo的名称"+i);
                user.put("vo",vo);
            }
            list.add(user);
        }
        map.put("total",100);//总数据条数===》select count(*)
        map.put("rows",list);
        return map;
    }

    @RequestMapping("/getTreeData")
    public List<Map<String,Object>> getTreeData(Integer id){
        List<Map<String,Object>> list= new ArrayList<Map<String,Object>>();
        for(int i=0;i<3;i++){
            Map<String,Object> node= new HashMap<String,Object>();
            node.put("id",i+1);
            node.put("text","节点"+i);
            node.put("state","open");
            if(i%2==0){
                List<Map<String,Object>> nodelist= new ArrayList<Map<String,Object>>();
                for(int j=0;j<4;j++){
                    Map<String,Object> node1= new HashMap<String,Object>();
                    node1.put("id",j+10);
                    node1.put("text","子节点"+j);
                    node1.put("state","open");
                    node1.put("checked",false);
                    nodelist.add(node1);
                }
                node.put("children",nodelist);
            }
            list.add(node);
        }
        return list;

    }

    @RequestMapping("/getIds")
    public String getIds(@RequestParam(name = "ids[]") Integer[] ids){
        System.out.println(ids);
        return "ok";
    }


}